package com.ruoyi.resturant.service.impl;

import com.ruoyi.resturant.domain.ResShop;
import com.ruoyi.resturant.mapper.ResShopMapper;
import com.ruoyi.resturant.service.IResShopService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * 店铺Service业务层处理
 *
 * @author Daniel
 * @date 2023-09-27
 */
@Service
public class ResShopServiceImpl implements IResShopService {

    public static Logger log = LoggerFactory.getLogger(ResShopServiceImpl.class);

    // 初始化数据
    private final static Map<Integer, ResShop> resShops = new LinkedHashMap<Integer, ResShop>();

    {
        resShops.put(1, new ResShop(1L, "烤冷面", "B2-201", "15888888888"));
        resShops.put(2, new ResShop(2L, "土豆粉", "B2-202", "15666666666"));
    }


    /**
     * 根据店铺ID查询店铺
     *
     * @param id 店铺主键
     * @return 店铺
     */
    @Override
    public ResShop selectResShopById(Long id) {
        return resShops.get(id.intValue());
    }

    /**
     * 查询店铺列表
     *
     * @param shopName 商铺名称
     * @return 店铺
     */
    @Override
    public List<ResShop> selectResShopByParam(String shopName) {
        List<ResShop> resShopLst = new ArrayList<ResShop>(resShops.values());
        return resShopLst;
    }

    /**
     * 新增店铺
     *
     * @param resShop 店铺
     * @return 结果
     */
    @Override
    public int insertResShop(ResShop resShop) {
        resShop.setCreateTime(new Date());
        // TODO 0：插入成功
        return 0;
    }

    @Autowired
    ResShopMapper mapper;

    @Override
    public List<ResShop> selectShopList(ResShop resShop) {
        return mapper.selectResShopList(resShop);
    }

    @Override
    public List<ResShop> selectResShopList2(ResShop resShop) {

        List<ResShop> result  =  mapper.selectResShopList2(resShop);
        if(result.size() <= 0) {
            log.error("23201012918葛晓丹 没有查询到任何的店铺");
        }else {
            log.info("23201012918葛晓丹  查询到了店铺，查询到的是：" + result.get(0).getName());
        }
        return result;
    }


    @Override
    public int addResShop(ResShop resShop) {
        return mapper.addResShop(resShop);
    }


    @Override
    public List<ResShop> selectResShop(String resShop) {
        return mapper.selectResShop(resShop);
    }

    /**
     * 修改店铺
     *
     * @param resShop 店铺
     * @return 结果
     */

    @Override
    public int updateResShop(ResShop resShop) {
        return mapper.updateResShop(resShop);
    }

    /**
     * 删除店铺信息
     *
     * @param id 店铺主键
     * @return 结果
     */
    @Override
    public int deleteResShopById(int id) {
        return 0;
    }



}
